package com.xli.organ.user.frameuser.mapper;

import com.xli.organ.user.frameuser.entity.FrameUser;
import com.xli.organ.user.frameuser.entity.UserCache;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface IUserCacheMapper {

    IUserCacheMapper INSTANCE = Mappers.getMapper(IUserCacheMapper.class);

    UserCache toCacheEntity(FrameUser frameUser);

    List<UserCache> toCacheList(List<FrameUser> frameUserList);

    List<FrameUser> toEntityList(List<UserCache> userCacheList);

    default List<FrameUser> toEntityList(List<UserCache> cacheList, Function<Long, FrameUser> query) {
        return cacheList.stream().map(cache -> query.apply(cache.getId())).collect(Collectors.toList());
    }
}
